package com.mobile.collect.db;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.mobile.collect.beans.DevicePicInfo;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "DEVICE_PIC_INFO".
*/
public class DevicePicInfoDao extends AbstractDao<DevicePicInfo, Long> {

    public static final String TABLENAME = "DEVICE_PIC_INFO";

    /**
     * Properties of entity DevicePicInfo.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property _ID = new Property(0, Long.class, "_ID", true, "_id");
        public final static Property ParentId = new Property(1, Long.class, "parentId", false, "PARENT_ID");
        public final static Property UnitName = new Property(2, String.class, "unitName", false, "UNIT_NAME");
        public final static Property DeviceName = new Property(3, String.class, "deviceName", false, "DEVICE_NAME");
        public final static Property Distance = new Property(4, String.class, "distance", false, "DISTANCE");
        public final static Property Reference = new Property(5, String.class, "reference", false, "REFERENCE");
        public final static Property Label = new Property(6, String.class, "label", false, "LABEL");
        public final static Property Direction = new Property(7, String.class, "direction", false, "DIRECTION");
        public final static Property Floor = new Property(8, String.class, "floor", false, "FLOOR");
        public final static Property Status = new Property(9, String.class, "status", false, "STATUS");
        public final static Property PicPath = new Property(10, String.class, "picPath", false, "PIC_PATH");
        public final static Property PicNo = new Property(11, String.class, "picNo", false, "PIC_NO");
        public final static Property PicBitMapWidth = new Property(12, int.class, "picBitMapWidth", false, "PIC_BIT_MAP_WIDTH");
        public final static Property PicBitmapHeight = new Property(13, int.class, "picBitmapHeight", false, "PIC_BITMAP_HEIGHT");
        public final static Property PointCount = new Property(14, long.class, "pointCount", false, "POINT_COUNT");
        public final static Property LableIsRepeat = new Property(15, boolean.class, "lableIsRepeat", false, "LABLE_IS_REPEAT");
        public final static Property IsCopy = new Property(16, boolean.class, "isCopy", false, "IS_COPY");
        public final static Property CreateTime = new Property(17, long.class, "createTime", false, "CREATE_TIME");
        public final static Property SortIndex = new Property(18, int.class, "sortIndex", false, "SORT_INDEX");
    }

    private DaoSession daoSession;

    private Query<DevicePicInfo> deviceInfo_DevicePicListQuery;

    public DevicePicInfoDao(DaoConfig config) {
        super(config);
    }
    
    public DevicePicInfoDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = daoSession;
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"DEVICE_PIC_INFO\" (" + //
                "\"_id\" INTEGER PRIMARY KEY ," + // 0: _ID
                "\"PARENT_ID\" INTEGER," + // 1: parentId
                "\"UNIT_NAME\" TEXT," + // 2: unitName
                "\"DEVICE_NAME\" TEXT," + // 3: deviceName
                "\"DISTANCE\" TEXT," + // 4: distance
                "\"REFERENCE\" TEXT," + // 5: reference
                "\"LABEL\" TEXT," + // 6: label
                "\"DIRECTION\" TEXT," + // 7: direction
                "\"FLOOR\" TEXT," + // 8: floor
                "\"STATUS\" TEXT," + // 9: status
                "\"PIC_PATH\" TEXT," + // 10: picPath
                "\"PIC_NO\" TEXT," + // 11: picNo
                "\"PIC_BIT_MAP_WIDTH\" INTEGER NOT NULL ," + // 12: picBitMapWidth
                "\"PIC_BITMAP_HEIGHT\" INTEGER NOT NULL ," + // 13: picBitmapHeight
                "\"POINT_COUNT\" INTEGER NOT NULL ," + // 14: pointCount
                "\"LABLE_IS_REPEAT\" INTEGER NOT NULL ," + // 15: lableIsRepeat
                "\"IS_COPY\" INTEGER NOT NULL ," + // 16: isCopy
                "\"CREATE_TIME\" INTEGER NOT NULL ," + // 17: createTime
                "\"SORT_INDEX\" INTEGER NOT NULL );"); // 18: sortIndex
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"DEVICE_PIC_INFO\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, DevicePicInfo entity) {
        stmt.clearBindings();
 
        Long _ID = entity.get_ID();
        if (_ID != null) {
            stmt.bindLong(1, _ID);
        }
 
        Long parentId = entity.getParentId();
        if (parentId != null) {
            stmt.bindLong(2, parentId);
        }
 
        String unitName = entity.getUnitName();
        if (unitName != null) {
            stmt.bindString(3, unitName);
        }
 
        String deviceName = entity.getDeviceName();
        if (deviceName != null) {
            stmt.bindString(4, deviceName);
        }
 
        String distance = entity.getDistance();
        if (distance != null) {
            stmt.bindString(5, distance);
        }
 
        String reference = entity.getReference();
        if (reference != null) {
            stmt.bindString(6, reference);
        }
 
        String label = entity.getLabel();
        if (label != null) {
            stmt.bindString(7, label);
        }
 
        String direction = entity.getDirection();
        if (direction != null) {
            stmt.bindString(8, direction);
        }
 
        String floor = entity.getFloor();
        if (floor != null) {
            stmt.bindString(9, floor);
        }
 
        String status = entity.getStatus();
        if (status != null) {
            stmt.bindString(10, status);
        }
 
        String picPath = entity.getPicPath();
        if (picPath != null) {
            stmt.bindString(11, picPath);
        }
 
        String picNo = entity.getPicNo();
        if (picNo != null) {
            stmt.bindString(12, picNo);
        }
        stmt.bindLong(13, entity.getPicBitMapWidth());
        stmt.bindLong(14, entity.getPicBitmapHeight());
        stmt.bindLong(15, entity.getPointCount());
        stmt.bindLong(16, entity.getLableIsRepeat() ? 1L: 0L);
        stmt.bindLong(17, entity.getIsCopy() ? 1L: 0L);
        stmt.bindLong(18, entity.getCreateTime());
        stmt.bindLong(19, entity.getSortIndex());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, DevicePicInfo entity) {
        stmt.clearBindings();
 
        Long _ID = entity.get_ID();
        if (_ID != null) {
            stmt.bindLong(1, _ID);
        }
 
        Long parentId = entity.getParentId();
        if (parentId != null) {
            stmt.bindLong(2, parentId);
        }
 
        String unitName = entity.getUnitName();
        if (unitName != null) {
            stmt.bindString(3, unitName);
        }
 
        String deviceName = entity.getDeviceName();
        if (deviceName != null) {
            stmt.bindString(4, deviceName);
        }
 
        String distance = entity.getDistance();
        if (distance != null) {
            stmt.bindString(5, distance);
        }
 
        String reference = entity.getReference();
        if (reference != null) {
            stmt.bindString(6, reference);
        }
 
        String label = entity.getLabel();
        if (label != null) {
            stmt.bindString(7, label);
        }
 
        String direction = entity.getDirection();
        if (direction != null) {
            stmt.bindString(8, direction);
        }
 
        String floor = entity.getFloor();
        if (floor != null) {
            stmt.bindString(9, floor);
        }
 
        String status = entity.getStatus();
        if (status != null) {
            stmt.bindString(10, status);
        }
 
        String picPath = entity.getPicPath();
        if (picPath != null) {
            stmt.bindString(11, picPath);
        }
 
        String picNo = entity.getPicNo();
        if (picNo != null) {
            stmt.bindString(12, picNo);
        }
        stmt.bindLong(13, entity.getPicBitMapWidth());
        stmt.bindLong(14, entity.getPicBitmapHeight());
        stmt.bindLong(15, entity.getPointCount());
        stmt.bindLong(16, entity.getLableIsRepeat() ? 1L: 0L);
        stmt.bindLong(17, entity.getIsCopy() ? 1L: 0L);
        stmt.bindLong(18, entity.getCreateTime());
        stmt.bindLong(19, entity.getSortIndex());
    }

    @Override
    protected final void attachEntity(DevicePicInfo entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public DevicePicInfo readEntity(Cursor cursor, int offset) {
        DevicePicInfo entity = new DevicePicInfo( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // _ID
            cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1), // parentId
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // unitName
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // deviceName
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // distance
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // reference
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // label
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // direction
            cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8), // floor
            cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9), // status
            cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10), // picPath
            cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11), // picNo
            cursor.getInt(offset + 12), // picBitMapWidth
            cursor.getInt(offset + 13), // picBitmapHeight
            cursor.getLong(offset + 14), // pointCount
            cursor.getShort(offset + 15) != 0, // lableIsRepeat
            cursor.getShort(offset + 16) != 0, // isCopy
            cursor.getLong(offset + 17), // createTime
            cursor.getInt(offset + 18) // sortIndex
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, DevicePicInfo entity, int offset) {
        entity.set_ID(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setParentId(cursor.isNull(offset + 1) ? null : cursor.getLong(offset + 1));
        entity.setUnitName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setDeviceName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setDistance(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setReference(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setLabel(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setDirection(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setFloor(cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8));
        entity.setStatus(cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9));
        entity.setPicPath(cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10));
        entity.setPicNo(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11));
        entity.setPicBitMapWidth(cursor.getInt(offset + 12));
        entity.setPicBitmapHeight(cursor.getInt(offset + 13));
        entity.setPointCount(cursor.getLong(offset + 14));
        entity.setLableIsRepeat(cursor.getShort(offset + 15) != 0);
        entity.setIsCopy(cursor.getShort(offset + 16) != 0);
        entity.setCreateTime(cursor.getLong(offset + 17));
        entity.setSortIndex(cursor.getInt(offset + 18));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(DevicePicInfo entity, long rowId) {
        entity.set_ID(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(DevicePicInfo entity) {
        if(entity != null) {
            return entity.get_ID();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(DevicePicInfo entity) {
        return entity.get_ID() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "devicePicList" to-many relationship of DeviceInfo. */
    public List<DevicePicInfo> _queryDeviceInfo_DevicePicList(Long parentId) {
        synchronized (this) {
            if (deviceInfo_DevicePicListQuery == null) {
                QueryBuilder<DevicePicInfo> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.ParentId.eq(null));
                deviceInfo_DevicePicListQuery = queryBuilder.build();
            }
        }
        Query<DevicePicInfo> query = deviceInfo_DevicePicListQuery.forCurrentThread();
        query.setParameter(0, parentId);
        return query.list();
    }

}
